package com.utils;

/**
 * @Author:Domen
 * @Date:2024/5/23 16:52
 */

import lombok.Data;
import org.springframework.stereotype.Service;

/**
 * 封装json对象，所有返回结果都使用它
 * .
 */
@Service
@Data
public class JsonResult<T> {

    private boolean success;// 是否成功标志

    private T data;// 成功时返回的数据

    private String error;// 错误信息

    public JsonResult() {
    }

    // 成功时的构造器
    public JsonResult(boolean success, T data) {
        this.success = success;
        this.data = data;
    }

    // 错误时的构造器
    public JsonResult(boolean success, String error) {
        this.success = success;
        this.error = error;
    }

    public boolean isSuccess() {
        return success;
    }

    @Override
    public String toString() {
        return "JsonResult [success=" + success + ", data=" + data + ", error=" + error + "]";
    }

}

